package edu.cqie.smartfarm.controller;


import edu.cqie.smartfarm.dto.FenceDTO;
import edu.cqie.smartfarm.dto.FenceQueryDTO;
import edu.cqie.smartfarm.dto.FenceUpdateDTO;
import edu.cqie.smartfarm.result.PageVO;
import edu.cqie.smartfarm.result.R;
import edu.cqie.smartfarm.service.IFenceService;
import edu.cqie.smartfarm.vo.FenceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyw
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/fence")
@RequiredArgsConstructor
@Api(tags = "围栏管理")
public class FenceController {
    private final IFenceService fenceService;

    /**
     * 获取围栏列表
     */
    @ApiOperation(value = "获取围栏列表")
    @GetMapping("/list")
    public R<PageVO<FenceVO>> getFenceList(FenceQueryDTO fenceQueryDTO) {
        PageVO<FenceVO> fenceList = fenceService.getFenceList(fenceQueryDTO);
        return R.Success(fenceList);
    }

    /**
     * 添加围栏
     */
    @ApiOperation(value = "添加围栏")
    @PostMapping("/add")
    public R addFence(@RequestBody @Validated FenceDTO fenceDTO){
        fenceService.addFence(fenceDTO);
        return R.Success();
    }

    /**
     * 修改围栏
     */
    @ApiOperation(value = "修改围栏")
    @PutMapping("/update")
    public R updateFence(@RequestBody @Validated FenceUpdateDTO fenceUpdateDTO){
        fenceService.updateFence(fenceUpdateDTO);
        return R.Success();
    }
}
